﻿
'Imports System.Web
Imports System.Web.Security
Imports System.Security.Principal

Public Class frmLogin

  Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
    Me.Dispose()
    Me.Close()
  End Sub

  Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
    If Membership.ValidateUser(txtUsuario.Text, txtPass.Text) Then
      'MsgBox("Usuario Valido", MsgBoxStyle.Information, "Validación de usuario")

      'Se toma el usuario del asp.net membership y se lo introduce en
      'el sistema de membership de windows. A partir de ahora va a estar disponible
      'para toda la aplicacion desde Threading.Thread.CurrentPrincipal.Identity.Name.
      ' Obtenido desde: http://www.theproblemsolver.nl/usingthemembershipproviderinwinforms.htm
      Dim identity As New GenericIdentity(txtUsuario.Text)
      Dim principal As New RolePrincipal(identity)
      Threading.Thread.CurrentPrincipal = principal


      Me.Finalize()
      Me.Close()
      My.Forms.frmMainMDISimpleMenu.Show()


      'Dim objVentana As frmContenedor = New frmContenedor
      'objVentana.Parent = Me
      'objVentana.Show()


    Else
      MsgBox("Usuario Inválido", MsgBoxStyle.Exclamation, "Validación de usuario")
    End If

  End Sub


End Class